<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$(document).ready(function() {
		$("#saleRegisterForm").submit(function(){
			if($("#title").val()==""){
				alert("책제목을 입력하세요");
				return false; 
			}
			if($("#writer").val()==""){
				alert("저자를 입력하세요");
				return false; 
			}
			if($("#publisher").val()==""){
				alert("출판사를 입력하세요");
				return false; 
			}
			if($("#price").val()==""){
				alert("희망가격을 입력하세요");
				return false; 
			}
			if(isNaN($("#price").val())){
				alert("희망가격은 숫자로 입력하세요");
				return false;
			}
		});
		$("#cancel").click(function(){
			if(confirm("취소하겠습니까?")){
				location.href="book_recent_list.do";
			}
		});
		$("#fillContentBtn").click(function() {
			$.ajax({
				type : "get",
				url : "book_api_proxy.do",
				crossDomain : true,
				dataType : "json",
				data : "query=" + $("#isbn").val(),
				success : function(data){
					$("#title").val(data.channel.item[0].title);
					$("#writer").val(data.channel.item[0].author);
					$("#publisher").val(data.channel.item[0].pub_nm);
					$("#onlinePrice").text("정가 - "+data.channel.item[0].list_price+"원");
					var coverUrl=data.channel.item[0].cover_l_url;
					$("#image").val(data.channel.item[0].cover_l_url);
					$("#coverUrl").html("<img src='"+coverUrl+"' id='image' name='image'>");
				},
				error:function(xhr,status,error){
					alert("error : "+xhr.status);
				}
			});//ajax
		});
	});
</script>

<form id="saleRegisterForm" action="book_salebook_register.do" method="post">
<fieldset>
<legend><h2>판매도서등록</h2></legend>
<br>
	<table cellpadding='5'>
		<tr>
			<td align="right"><b>ISBN</b></td>
			<td style="background-color:#F2CB61;"><input type="text" name="isbn" id="isbn" style="width:250px;">
			<input type="button" id="fillContentBtn" value="ISBN으로 아래내용 채우기" style="background-color:#997000; color:white;"></td>
		</tr>
		<tr><td colspan='2'><hr></td></tr>
		<tr>
			<td align="right">책 표지</td>
			<td><span id="coverUrl">
				<img src="${initParam.root }img/ex_mark.png" width="12px"> ISBN으로 도서 정보를 입력하면, 책 표지가 보입니다.</span>
				<input type="hidden" id="image" name="image" value="0"></td>
		</tr>
		<tr>
			<td align="right">책 제목</td>
			<td><input type="text" name="title" id="title"  style="width:430px;"></td>
		</tr>
		<tr>
			<td align="right">저자</td>
			<td><input type="text" name="writer" id="writer" style="width:430px;"></td>
		</tr>
		<tr>
			<td align="right">출판사</td>
			<td><input type="text" name="publisher" id="publisher" style="width:430px;"></td>
		</tr>
		<tr><td colspan='2'><hr></td></tr>
		<tr>
			<td>희망가격</td>
			<td><input type="text" name="price" id="price" style="width:250px;">
			&nbsp;
			<img src="${initParam.root }img/ex_mark.png" width="12px"> <span id="onlinePrice">현재 온라인 정가 안내</span></td>
		</tr>
		<tr>
			<td align="right">책상태</td>
			<td><select id="status" name="status" style="width:253px;">
					<option value="매우좋음">매우좋음</option>
					<option value="좋음">좋음</option>
					<option value="보통">보통</option>
					<option value="나쁨">나쁨</option>
					<option value="매우나쁨">매우나쁨</option>
			</select></td>
		</tr>
		<tr>
			<td align="right">개정정보</td>
			<td><select id="version" name="version" style="width:253px;">
					<option value="초판">초판</option>
					<option value="개정2판">개정2판</option>
					<option value="3판">3판</option>
					<option value="4판">4판</option>
					<option value="5판">5판</option>
					<option value="6판">6판</option>
					<option value="7판">7판</option>
					<option value="8판">8판</option>
					<option value="9판">9판</option>
					<option value="10판">10판</option>
					<option value="11판">11판</option>
					<option value="12판">12판</option>
					<option value="13판">13판</option>
					<option value="14판">14판</option>
					<option value="15판">15판</option>
					<option value="16판">16판</option>
					<option value="17판">17판</option>
					<option value="18판">18판</option>
					<option value="19판">19판</option>
					<option value="20판">20판</option>
			</select></td>
		</tr>
	</table>
	<br><hr><br>
	<font size='2'>
	<img src="${initParam.root }img/ex_mark.png" width="12px"> ISBN으로 간편하게 등록하실 책 정보를 입력하실 수 있습니다.<br>
	<img src="${initParam.root }img/ex_mark.png" width="12px"> 작성하신 도서정보는 '나의 도서관리'에서 공개여부를 변경하실 수 있습니다.
	</font>
	<br><br>	
	<div style="background-color: #EAEAEA">
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="submit" value="도서등록" style="font-family:'맑은 고딕'; width:100px; height:40px; background-color: #1F50B5; color:white;">
		<input type="button" value="등록 취소" id="cancel" style="font-family:'맑은 고딕'; width:100px; height:40px; background-color: #C90000; color:white;">
	</div>
	
	</fieldset>
</form>